package edu.rmit.service.impl;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.List;

import edu.rmit.dao.IUserDAO;
import edu.rmit.dao.impl.UserDAOImpl;
import edu.rmit.domain.User;
import edu.rmit.service.IUserService;

/**
 * This class implements the user operation. Like get user, change the user
 * status, register user, and get user by its status.
 * 
 * @author Joey George
 * @version 1.0
 */
@SuppressWarnings("serial")
public class UserServiceImpl extends UnicastRemoteObject implements
		IUserService {
	
	/**
	 * This instance can be manipulated to implement the database opertion.
	 */
	private IUserDAO userInfoDAO;

	/**
	 * The constructor to initialize a database operation instance.
	 * @throws RemoteException
	 */
	public UserServiceImpl() throws RemoteException {
		userInfoDAO = new UserDAOImpl();
	}

	/**
	 * This method implements the operation to change an user's status.
	 * 
	 * @param userName
	 *            The user name of which you want to changed.
	 * @param destinationStatus
	 *            The destination status which you want to changed to.
	 */
	@Override
	public void changeActiveStatus(String userName, boolean destinationStatus)
			throws RemoteException {
		userInfoDAO.changeActiveStatus(userName, destinationStatus);
	}
	
	/**
	 * This method defines the operation to change an user's login status.
	 * 
	 * @param userName
	 *            The user name of which you want to changed.
	 * @param destinationStatus
	 *            The destination status which you want to changed to.
	 */
	public void changeLoginStatus(String userName, boolean destinationStatus){
		userInfoDAO.changeLoginStatus(userName, destinationStatus);
	}

	/**
	 * This method implements to create a new account for a user
	 * 
	 * @param userName
	 *            The user name which you can use to login.
	 * @param password
	 *            The password which you can use this to login.
	 * @param firstName
	 *            The first name of the user.
	 * @param lastName
	 *            The last name of the user.
	 * @param isActive
	 *            The status of the user.
	 * @return A particular which contains this attribute.
	 */
	@Override
	public void register(String userName, String password, String firstName,
			String lastName) throws RemoteException {
		userInfoDAO.createAccount(userName, password, firstName,
				lastName, true);
	}

	/**
	 * This method implements the operation to get an user by its user name.
	 * 
	 * @param userName
	 *            The user name of particular user.
	 * @return The user object which represented by the user name.
	 */
	@Override
	public User getUser(String userName)
			throws RemoteException {
		return userInfoDAO.getUserInfo(userName);
		
	}

	/**
	 * This method implements the operation to get the users by its status.
	 * 
	 * @param isActive
	 *            The destination status which you want to get.
	 * @return A list of users which status is currently in this status.
	 */
	@Override
	public List<User> getUsersByActiveStatus(boolean isActive) 
			throws RemoteException {
		return userInfoDAO.getUsersByActiveStatus(isActive);
	}
	
}
